package org.shijiagen.manager.service.impl;

import lombok.RequiredArgsConstructor;
import org.shijiagen.clients.CategoryClient;
import org.shijiagen.manager.service.CategoryService;
import org.shijiagen.param.PageParam;
import org.shijiagen.pojo.Category;
import org.shijiagen.utils.R;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class CategoryServiceImpl implements CategoryService {


    public final CategoryClient categoryClient;

    @Override
    @Cacheable(value = "list.category",key = "#param.currentPage+'-'+#param.pageSize")
    public R pageList(PageParam param) {
        return categoryClient.listPage(param);
    }

    @Override
    @CacheEvict(value = "list.category", allEntries = true)
    public R save(Category category) {
        return categoryClient.save(category);
    }

    @Override
    @CacheEvict(value = "list.category", allEntries = true)
    public R remove(Integer categoryId) {
        return categoryClient.remove(categoryId);
    }

    @Override
    @CacheEvict(value = "list.category", allEntries = true)
    public R update(Category category) {
        return categoryClient.update(category);
    }
}
